Skip to content

Six-equation pressure relaxation: skip phases with non-positive partial density - #2408

Open
wilfonba wants to merge 1 commit into
MFlowCode:masterfrom
wilfonba:sixEqRelaxGuard
Open

wilfonba wants to merge 1 commit into
MFlowCode:masterfrom
wilfonba:sixEqRelaxGuard

Conversation

@wilfonba

Copy link
Copy Markdown
Collaborator

Contribution Policy

All contributions are expected to demonstrate:

  • A clear understanding of the codebase
  • Alignment with product direction
  • Thoughtful reasoning behind changes
  • Evidence of real-world usage or hands-on experience with the problem

If these expectations are not met, we would prefer to implement the changes ourselves rather than spend time reviewing low-effort submissions.

Summary

s_equilibrate_pressure (src/simulation/m_pressure_relaxation.fpp) includes a phase in the six-equation pressure relaxation whenever its volume fraction exceeds sgm_eps. With mpp_lim = F, a phase that is absent from a cell is carried at round-off, and its partial density can come out negative while its volume fraction sits just above sgm_eps. The isentrope density rho_K_s = alpha_rho/alpha * (...) of that phase is then negative, the routine flags the cell as unusable, and the run stops with "Pressure relaxation produced a non-physical phasic density". The phase has no mass to equilibrate, so the abort is spurious.

This PR adds f_phase_active: a phase takes part in the relaxation only if its volume fraction exceeds sgm_eps and its partial density is positive. The five existing alpha > sgm_eps checks in s_equilibrate_pressure call it. An inactive phase contributes nothing to the Newton residual and keeps its volume fraction; s_correct_internal_energies is unchanged and still resets every phase's internal energy from the relaxed pressure.

Where every phase with alpha > sgm_eps has positive partial density, the new condition equals the old one and results are unchanged. It is a CFD-result change only for runs that master aborts.

Verification

examples/1D_kapilashocktube (water at 1e9 Pa against air at 1e5 Pa, pure-fluid patches with alpha = 0/alpha_rho = 0 for the absent phase, mpp_lim = F, WENO5-M, HLLC, RK3, 1000 cells, 6025 steps), changed only by model_eqns: 6eq and removing alt_soundspeed. Serial CPU, NVHPC 26.3. "Master" is 7982f2d.

build outcome
master aborts at step 2280 of 6025: "Pressure relaxation produced a non-physical phasic density"
this PR completes; all fields finite
  • Cause confirmed. A temporary print on this branch, at cells where a phase has alpha > sgm_eps but is not active, first fires at step 2280, the step master aborts on: cell 757 (inside the air region), water, alpha = 1.009e-16, alpha_rho = -1.412e-16. It fires 2338 times over the rest of the run.
  • Identical until then. The conservative variables of master and this branch are bitwise identical at steps 0, 1000, 2000, 2200, 2250 and 2275.
  • The guard does not degrade the solution. Against the unmodified five-equation example at the same resolution, the relative L1 differences of the six-equation run are of the same size before the guard first acts (step 2200) as at the end (step 6025):
density velocity pressure water volume fraction
step 2200 (guard not yet active) 4.7e-4 4.1e-3 4.4e-4 4.1e-5
step 6025 6.5e-4 1.8e-3 1.1e-3 3.8e-5

The interface (alpha = 0.5) is in the same cell, 816, in both at the final step, and the water and air masses at the final step equal their initial values to the 11 digits printed.

Not verified: GPU builds (the change adds one GPU_ROUTINE seq function called from an existing seq routine, but it was not compiled or run on a GPU); 2D or 3D cases that trigger the guard; cases with mpp_lim = T, where s_correct_volume_fractions already zeroes a phase with negative partial density before the relaxation; state-dependent equations of state in a cell where the guard acts.

Type of change

  • Bug fix

Testing

CPU, NVHPC 26.3: the 28 suite cases that use model_eqns = 3 pass against the committed goldens, none regenerated. 18 of them reach this routine; the other 10 are phase-change cases, which use relax = T and bypass it. Plus the shock-tube comparison above.

Related: split out of #2098, which carries the same change.

This PR was made with Claude Code (AI).

🤖 Generated with Claude Code

@wilfonba
wilfonba requested a review from a team as a code owner November 22, 2026 21:13
@wilfonba
wilfonba requested review from sbryngelson and removed request for a team November 22, 2026 21:13
@github-actions

Copy link
Copy Markdown

Lines of Code

File Lines Diff
src/simulation/m_pressure_relaxation.fpp 223 +7
Directory Lines Diff
simulation 41872 +7
total 61947 +7

@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: ea9913d

Files changed:

  • 1
  • src/simulation/m_pressure_relaxation.fpp

Findings:

  • medium src/simulation/m_pressure_relaxation.fpp: The new f_phase_active comment says a phase with negative partial density "keeps its state". That holds only inside s_equilibrate_pressure. s_correct_internal_energies (line ~306) still loops over all phases and calls s_phase_internal_energy with the raw alpha_i and alpha_rho_i, then overwrites int_en. This now includes the phases f_phase_active skips. Those are phases with alpha > sgm_eps and alpha_rho <= 0, which only reach this point when mpp_lim is off, since s_correct_volume_fractions zeroes them otherwise. For such phases the internal energy is recomputed from a negative density, so the state is not kept. Use the same predicate in that loop, or confirm that s_phase_internal_energy handles alpha_rho <= 0. I am moderately sure of this. I did not read s_phase_internal_energy.
  • medium src/simulation/m_pressure_relaxation.fpp: f_phase_active is now false for more phases. If it is false for all of them, the Newton loop leaves f_pres = -1 and df_pres = 0, so pres_relax - f_pres/df_pres divides by zero. This is possible in a cell where every phase has alpha_rho <= 0. Before the change, a cell needed alpha <= sgm_eps in every phase, which cannot happen when the volume fractions sum to 1. The usable check does not catch it, because it only inspects active phases. The result is a NaN pres_relax that unusable does not flag. Consider flagging unusable when no phase is active. I am moderately sure of this.
  • medium src/simulation/m_pressure_relaxation.fpp: With the new filter, the active phases' alpha values are rewritten to alpha_rho/rho_s, while the skipped phase keeps its positive alpha. The volume fractions then no longer sum to 1, and nothing in this path renormalizes them. Check that this is intended for the skipped-phase case. I am less sure of this.

@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.14%. Comparing base (398733e) to head (ea9913d).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/simulation/m_pressure_relaxation.fpp 50.00% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2408   +/-   ##
=======================================
  Coverage   66.14%   66.14%           
=======================================
  Files         112      112           
  Lines       31093    31096    +3     
  Branches     4749     4749           
=======================================
+ Hits        20567    20570    +3     
  Misses       6675     6675           
  Partials     3851     3851           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant